
//
// 130227 - AH - Created.
//

package org.japril.gim;

/**
 * <p>
 *   Default
 *   {@link ItemItem} implementation.
 * </p>
 * @author Arne Halvorsen (AH)
 */
public class DefaultItemItem implements ItemItem 
{
  private final int m_lid;
  
  private final String m_ltype;
  
  private final int m_rid;
  
  private final String m_rType;
    
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param rightId   {@link #getLeftId()}.
   * @param leftType  {@link #getLeftRole()}.
   * @param leftId    {@link #getRightId()}.
   * @param rightType {@link #getRightRole()}.
   * @throws IllegalArgumentException If {@code leftId<0 || rightId<0},
   *         {@code leftType} is the empty string or {@code leftType} is the 
   *         empty string. 
   */
  public DefaultItemItem(int leftId, String leftType, int rightId,
    String rightType)
  {
    if (leftId<0)
    {
      throw new IllegalArgumentException("leftKey<0 : "+leftId);
    }
    if (leftType==null)
    {
      throw new IllegalArgumentException("leftType");
    }
    if (rightId<0)
    {
      throw new IllegalArgumentException("rightKey<0 : "+leftId);
    }
    if (rightType==null)
    {
      throw new IllegalArgumentException("rightType");
    }
    
    leftType=leftType.trim();
    rightType=rightType.trim();
    
    if (leftType==null)
    {
      throw new IllegalArgumentException("leftType is the empty string");
    }
    if (rightType==null)
    {
      throw new IllegalArgumentException("rightType is the empty string");
    }
    
    m_lid=leftId;
    m_ltype=(leftType.length()==0) ? null : leftType;
    m_rid=rightId;
    m_rType=(rightType.length()==0) ? null : rightType;
  }

  // Specified in ItemItem.
  public int getLeftId(){ return m_lid; }

  // Specified in ItemItem.
  public String getLeftRole(){ return m_ltype; }

  // Specified in ItemItem.
  public int getRightId(){ return m_rid; }
  
  // Specified in ItemItem.
  public String getRightRole(){ return m_rType; }
  
  @Override
  public String toString() 
  {
    StringBuilder sb=new StringBuilder();
    
    sb.append("lid=").append(m_lid).append(", ltype=").append(m_ltype)
      .append(", rid=").append(m_rid).append(", rtype=")
      .append(m_rType);
    
    return sb.toString();
  }
  
}
